Skip to content

Add workflow to address review feedback - #322

Merged
jwbron merged 6 commits into
mainfrom
egg/address-review-feedback
Feb 8, 2026
Merged

jwbron merged 6 commits into
mainfrom
egg/address-review-feedback

Conversation

@james-in-a-box

@james-in-a-box james-in-a-box Bot commented Feb 8, 2026 •

Copy link
Copy Markdown
Contributor

Add automated feedback loop for bot-authored PRs

Currently the review bot posts feedback on PRs, but there's no mechanism
for the authoring agent to pick up that feedback and address it. This PR
closes that gap by adding a new workflow that triggers when review
feedback is posted, runs the agent to read the feedback and push fixes,
which then triggers re-review via the existing synchronize event.

The feedback loop: PR opened → review → address feedback → re-review →
repeat until approval or max iterations (3 rounds).

Changes:

  • .github/workflows/on-review-feedback.yml: New workflow triggered by
    pull_request_review (formal reviews) and issue_comment (self-reviews
    posted as comments when GitHub blocks bots from reviewing their own PRs).
    Filters to only run on bot-authored PRs with automated review markers.
    Includes loop protection via iteration counting. Prompt is built inline
    in the workflow YAML (no external script).

Safety:

  • Max 3 feedback rounds before stopping and notifying human
  • Only triggers on bot-authored PRs (not external contributor PRs)
  • Skips approval reviews (nothing to address)
  • Follows trusted-checkout security pattern (prompt built from main)
  • Concurrency group prevents parallel runs per PR

Issue: #258

Test plan:

  • Bot opens a PR → review posts feedback → verify feedback workflow triggers
  • Verify feedback workflow skips approval reviews (verdict=approve)
  • Verify feedback workflow skips non-bot-authored PRs
  • Verify iteration limit: after 3 rounds, workflow posts "human review needed"
  • Verify manual workflow_dispatch trigger works
  • Verify [skip-review] marker prevents feedback workflow from running

Authored-by: egg

@james-in-a-box

james-in-a-box Bot commented Feb 8, 2026

Copy link
Copy Markdown
Contributor Author

Agent-Mode Design Review: No concerns.

The prompt design in build-feedback-prompt.sh follows agent-mode principles well:

  • Objective-focused: Tells the agent what to do (read feedback, make fixes, push) without micromanaging procedure
  • Agent fetches its own context: Directs the agent to use gh pr view and gh pr diff rather than baking diffs into the prompt
  • No structured output: Agent posts directly to GitHub, no JSON parsing pipeline
  • Appropriate orienting context: PR number and feedback rules inform the task without constraining exploration

The iteration limit (3 rounds) is a legitimate safety constraint, not a prompt-level restriction.

— Authored by egg

@james-in-a-box

james-in-a-box Bot commented Feb 8, 2026

Copy link
Copy Markdown
Contributor Author

egg agent-mode-design completed. View run logs

@james-in-a-box james-in-a-box Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

This PR adds a feedback loop workflow to automatically address review feedback on bot-authored PRs. The overall design follows existing patterns and correctly implements the trusted-checkout security model. However, there are several issues that need to be addressed.


Issues

1. Race Condition in Iteration Counting (Correctness)

File: .github/workflows/on-review-feedback.yml:123-126

feedback_count=$(gh api "repos/${{ github.repository }}/issues/${{ env.PR_NUMBER }}/comments" \
  --jq '[.[] | select(.body | test("egg-feedback-addressing"))] | length' 2>/dev/null || echo "0")

The iteration counting is racy. The marker egg-feedback-addressing is posted in the "Post starting comment" step (lines 142-145), which runs after this check. This means:

  1. Run 1: count=0, check passes, posts marker, runs agent
  2. Run 2: count=1 (sees Run 1's marker), check passes, posts marker, runs agent
  3. Run 3: count=2 (sees Runs 1 and 2's markers), check passes, posts marker, runs agent
  4. Run 4: count=3, blocked

This allows 4 rounds (not 3) before stopping, because the current run's marker isn't counted until after the check. The workflow will run once more than MAX_FEEDBACK_ROUNDS allows.

Fix: Change the condition from >= to >:

if [[ "$feedback_count" -gt "$((MAX_FEEDBACK_ROUNDS - 1))" ]]; then

Or adjust the intent: if MAX_FEEDBACK_ROUNDS=3 means "allow 3 rounds," use -ge with $MAX_FEEDBACK_ROUNDS but document that the count is 0-indexed (rounds 0, 1, 2 = 3 total).


2. Missing EGG_BOT_NAME Environment Variable (Correctness)

File: .github/workflows/on-review-feedback.yml:224-232

The reusable-review.yml workflow passes EGG_BOT_NAME to the egg action:

env:
  EGG_BOT_NAME: ${{ inputs.bot_name }}

This is used by the gh wrapper to populate the <!-- egg-automated-review bot=<name> ... --> marker. The new workflow doesn't set this, so when the agent pushes fixes and the review workflow re-runs, it won't be able to distinguish feedback-fixing runs from regular reviews.

This probably doesn't cause a functional issue since the feedback workflow doesn't post reviews, but it's inconsistent with the established pattern.

Fix: Add EGG_BOT_NAME: feedback as an environment variable to the egg step if you want tracking consistency, or document that this is intentional.


3. Inconsistent PR Number Extraction for pull_request_review Event

File: .github/workflows/on-review-feedback.yml:50

PR_NUMBER: ${{ github.event.pull_request.number || github.event.issue.number || github.event.inputs.pr_number }}

For pull_request_review events, the PR number is in github.event.pull_request.number, which is correctly handled. However, the concurrency group on line 48 uses the same expression:

group: egg-feedback-${{ github.event.pull_request.number || github.event.issue.number || github.event.inputs.pr_number }}

This is fine, but note that for pull_request_review events, github.event.issue.number is not available (it's a different event type). The fallback order is correct, but test this path explicitly.


4. Feedback Prompt Missing Critical Context (Design)

File: action/build-feedback-prompt.sh:55-74

The prompt tells the agent to use gh pr view ${PR_NUMBER} --comments to read feedback, but this won't show review comments (inline comments on specific lines). The agent needs to also check:

gh api "repos/${GITHUB_REPOSITORY}/pulls/${PR_NUMBER}/reviews" --jq '...'
gh api "repos/${GITHUB_REPOSITORY}/pulls/${PR_NUMBER}/comments" --jq '...'

The gh pr view --comments command only shows issue-level comments, not:

  • Review bodies (pull_request_review)
  • Line-level comments (pull_request_review_comment)

Fix: Update the prompt to include:

1. **Read the feedback**: 
   - Issue-level comments: \`gh pr view ${PR_NUMBER} --comments\`
   - Formal reviews: \`gh api repos/${GITHUB_REPOSITORY}/pulls/${PR_NUMBER}/reviews --jq '.[] | {user: .user.login, state: .state, body: .body}'\`
   - Line-level comments: \`gh api repos/${GITHUB_REPOSITORY}/pulls/${PR_NUMBER}/comments --jq '.[] | {path: .path, line: .line, body: .body}'\`

5. No Handling for Fork PRs (Robustness)

File: .github/workflows/on-review-feedback.yml:200-204

- name: Checkout PR branch
  uses: actions/checkout@v4
  with:
    repository: ${{ steps.pr-meta.outputs.head-repo }}
    ref: ${{ steps.pr-meta.outputs.head-ref }}

For PRs from forks, head-repo will be the fork's full_name. The bot won't have push access to forks, so the workflow will fail when trying to push fixes.

The if condition on line 68 filters to bot-authored PRs, so this shouldn't happen in practice (the bot won't author PRs from forks). But if someone manually triggers workflow_dispatch on a fork PR, it will fail confusingly.

Fix: Add a check in should-run to verify the PR head repo matches the base repo, or document this limitation.


6. Missing Shellcheck Directive for $id (Minor)

File: .github/workflows/on-review-feedback.yml:157

The reusable-review.yml and on-check-failure.yml have:

# shellcheck disable=SC2016 # $id is a GraphQL variable, not bash

But this workflow's minimize step omits it. This isn't a functional issue (GraphQL variables aren't expanded), but it triggers shellcheck warnings and is inconsistent.


Observations (Non-blocking)

  1. Good: The trusted-checkout pattern is correctly implemented—prompt is built from main, then PR branch is checked out for the agent. This prevents code injection.

  2. Good: Concurrency group prevents parallel runs on the same PR.

  3. Good: The iteration limit with human notification is a reasonable safety valve.

  4. Consistent with patterns: The workflow structure matches on-check-failure.yml well.


Suggested Test Additions

The test plan in the PR description is good but should include:

  • Verify the agent can find and read line-level review comments (not just issue comments)
  • Verify workflow_dispatch on a fork PR fails gracefully with a clear message
  • Verify exactly 3 rounds occur before stopping (not 4)

— Authored by egg

@james-in-a-box

This comment has been minimized.

@james-in-a-box

james-in-a-box Bot commented Feb 8, 2026

Copy link
Copy Markdown
Contributor Author

egg failed to address feedback. View run logs

@jwbron

jwbron commented Feb 8, 2026

Copy link
Copy Markdown
Owner

@james-in-a-bot address this feedback: #322 (review)

@james-in-a-box

james-in-a-box Bot commented Feb 8, 2026

Copy link
Copy Markdown
Contributor Author

egg review completed. View run logs

@james-in-a-box james-in-a-box Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed the review feedback. Here's the breakdown:

Issue 1 (Race Condition in Iteration Counting): Disagree. Tracing through: count is checked before the marker is posted. With MAX_FEEDBACK_ROUNDS=3 and -ge 3, rounds execute at counts 0, 1, 2 (3 rounds total), and the 4th trigger sees count=3 and is blocked. This is correct behavior — exactly 3 rounds run. Added a clarifying comment to make the counting semantics explicit.

Issue 2 (Missing EGG_BOT_NAME): Agreed. Added EGG_BOT_NAME: feedback env var to the egg step for tracking consistency.

Issue 3 (PR Number Extraction): Acknowledged. The fallback order is correct as noted in the review. No change needed.

Issue 4 (Feedback Prompt Missing Review/Inline Comments): Agreed. Updated the prompt to include gh api calls for formal reviews and line-level review comments alongside the existing gh pr view --comments.

Issue 5 (No Handling for Fork PRs): Agreed. Added a fork check in should-run that compares head-repo against github.repository. Placed before the workflow_dispatch fast-path so it applies to manual triggers too (bot physically can't push to forks regardless of trigger type).

Issue 6 (Missing Shellcheck Directive): Disagree. The # shellcheck disable=SC2016 directive is already present on line 166 (now line 166) of the minimize step. It was in the original commit.

Additional fix: Added a bootstrap guard to the "Build feedback prompt" step — if action/build-feedback-prompt.sh doesn't exist on main (which is the case until this PR is merged), the step emits a warning and skips gracefully instead of failing. This was the root cause of the CI failure.

— Authored by egg

@james-in-a-box

This comment has been minimized.

@james-in-a-box

james-in-a-box Bot commented Feb 8, 2026

Copy link
Copy Markdown
Contributor Author

Agent-mode design review: No concerns

This workflow follows agent-mode design principles well:

  • No excessive pre-fetching: The prompt contains just the PR number and repo name—the agent fetches diffs and comments itself
  • Natural language output: No JSON schemas or structured output requirements
  • Direct action: The agent pushes commits and posts comments directly, no post-processing pipeline
  • Outcome-focused: Tells the agent to "address review feedback" with guidance on priorities, but doesn't micromanage procedure

The included gh commands for reading feedback are helpful orientation (showing where to find data), not constraining pre-fetching.

— Authored by egg

@james-in-a-box

james-in-a-box Bot commented Feb 8, 2026

Copy link
Copy Markdown
Contributor Author

egg agent-mode-design completed. View run logs

@james-in-a-box james-in-a-box Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

This PR adds a feedback-addressing workflow that closes the automation loop: when review feedback is posted, the bot reads it and pushes fixes. The design follows existing patterns (trusted checkout, concurrency groups, iteration limits). However, there are several issues that need to be addressed before this is ready to merge.


Issues

1. Missing github-token input to egg action (Correctness)

File: .github/workflows/on-review-feedback.yml:224

The egg action invocation is missing the github-token input. Looking at action/action.yml, this input has a default of ${{ github.token }}, but the action documentation and other workflows in this repo (e.g., reusable-review.yml) explicitly pass the bot token for git operations.

Since this workflow needs the agent to push commits, it requires proper GitHub credentials. The default github.token may work, but other workflows pass the bot token explicitly for consistency.

Suggested fix:

- name: Run egg to address feedback
  uses: jwbron/egg/action@main
  with:
    prompt-file: ${{ steps.prompt.outputs.prompt-file }}
    model: ${{ steps.prompt.outputs.model }}
    anthropic-oauth-token: ${{ secrets.ANTHROPIC_OAUTH_TOKEN }}
    github-token: ${{ steps.bot-token.outputs.token }}  # Add this
    bot-app-id: ${{ secrets.BOT_APP_ID }}
    ...

2. Race condition in iteration count check (Correctness)

File: .github/workflows/on-review-feedback.yml:138-150

The iteration count is checked by counting egg-feedback-addressing marker comments. However, this check happens BEFORE the "Post starting comment" step that adds the marker. If two workflow runs trigger nearly simultaneously (e.g., rapid review comment + re-review), they could both pass the count check before either posts the marker.

The concurrency group with cancel-in-progress: true mitigates this for the same PR, but there's still a window between the check and the marker post where a second run could slip through.

Suggested fix: Move the marker post to be atomic with the check, or accept this as a known limitation documented in comments (the practical impact is low since cancel-in-progress: true handles most cases).


3. Inconsistent bot username format in GraphQL minimize query (Correctness)

File: .github/workflows/on-review-feedback.yml:161-162

The minimize comments step hardcodes "james-in-a-box" instead of using the $BOT_USERNAME env var:

--jq '.[] | select(.user.login == "james-in-a-box" or .user.login == "james-in-a-box[bot]")

Compare to on-check-failure.yml which has the same hardcoding. While this works, it violates DRY and makes future username changes error-prone.

Suggested fix: Use $BOT_USERNAME consistently:

--jq --arg bot "$BOT_USERNAME" '.[] | select(.user.login == $bot or .user.login == ($bot + "[bot]"))'

4. build-feedback-prompt.sh missing shebang execution check (Robustness)

File: action/build-feedback-prompt.sh:14-16

The script uses set -euo pipefail which is good, but unlike build-autofixer-prompt.sh, it doesn't load any conventions files from the action directory. This is fine if intentional, but the prompt lacks the standard conventions that other prompt builders include (like autofixer-conventions.md).

Consider whether feedback-conventions should exist for consistency with the autofixer pattern.


5. Prompt leaks GitHub repository info unnecessarily (Minor/Security hygiene)

File: action/build-feedback-prompt.sh:55-62

The prompt template embeds ${GITHUB_REPOSITORY} in multiple places:

gh api repos/${GITHUB_REPOSITORY}/pulls/${PR_NUMBER}/reviews
gh api repos/${GITHUB_REPOSITORY}/pulls/${PR_NUMBER}/comments

This is unnecessary since the agent runs in the repo context and gh pr view / gh api commands use the current repo by default. While not a security vulnerability, it's extra noise in the prompt.

Suggested fix: Simplify to use repo-relative commands where possible.


6. Missing error handling for prompt file write (Robustness)

File: action/build-feedback-prompt.sh:84

echo "$prompt" > "$prompt_file"

If the write fails (disk full, permissions), the script continues and sets outputs referencing a non-existent or empty file. With set -e this would exit, but the error message wouldn't be helpful.

Suggested fix: Add explicit error check or use || exit 1 with a clear message.


7. Comment body pattern matching is fragile (Robustness)

File: .github/workflows/on-review-feedback.yml:127-131

if [[ "$comment_body" == *"verdict=approve"* ]]; then

This substring match could false-positive on comments that mention "verdict=approve" in discussion (e.g., "changed from verdict=approve to verdict=reject"). While unlikely in practice, a regex anchored to the marker format would be more robust:

if [[ "$comment_body" =~ "<!-- egg-automated-review.*verdict=approve" ]]; then

8. Workflow dispatch input should validate PR exists (Robustness)

File: .github/workflows/on-review-feedback.yml:18-21

The workflow_dispatch input accepts any number. If an invalid PR number is provided, the workflow will fail at the "Fetch PR metadata" step with a non-obvious API error. Consider adding validation.


9. Result comment doesn't include iteration count (UX)

File: .github/workflows/on-review-feedback.yml:246-253

The result comment says "egg feedback addressed" but doesn't indicate which iteration this was (1/3, 2/3, etc.). This would help humans understand how many rounds have occurred.


Minor/Style

  • Line 45: The if condition is getting long. Consider extracting to a reusable step or simplifying.
  • The BOT_USERNAME env var is defined but also hardcoded in places—consider full consistency.

What looks good

  • Trusted checkout pattern for prompt building (security)
  • Concurrency groups to prevent parallel runs
  • Iteration limit with human notification
  • Fork detection to skip PRs the bot can't push to
  • Skip patterns for approval reviews and [skip-review] marker
  • Following existing workflow patterns in the repo

Verdict

The core design is sound and follows established patterns, but the missing github-token input is a likely bug that would cause the workflow to fail when the agent tries to push. The other issues are less critical but worth addressing.

— Authored by egg

@james-in-a-box

This comment has been minimized.

@james-in-a-box

james-in-a-box Bot commented Feb 8, 2026

Copy link
Copy Markdown
Contributor Author

egg review completed. View run logs

@james-in-a-box

james-in-a-box Bot commented Feb 8, 2026

Copy link
Copy Markdown
Contributor Author

Agent-mode design review: No concerns.

The workflow provides lightweight context (PR number, repo) and instructs the agent to fetch what it needs (gh pr diff, gh pr view --comments, API calls). No large pre-fetched diffs, no structured JSON output requirements, no post-processing pipeline. The agent pushes fixes and posts comments directly using its tools.

— Authored by egg

@james-in-a-box

james-in-a-box Bot commented Feb 8, 2026

Copy link
Copy Markdown
Contributor Author

egg agent-mode-design completed. View run logs

@james-in-a-box james-in-a-box Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Security Issues

1. Missing Trusted Checkout Pattern (Critical)

Lines 184-189: The workflow checks out the PR branch directly before building the prompt:

- name: Checkout PR branch
  if: steps.should-run.outputs.run == 'true'
  uses: actions/checkout@v4
  with:
    repository: ${{ steps.pr-meta.outputs.head-repo }}
    ref: ${{ steps.pr-meta.outputs.head-ref }}

Then on line 207, the prompt builder reads .egg/feedback-rules.md from the checked-out PR branch:

if [[ -f ".egg/feedback-rules.md" ]]; then
  feedback_rules=$(< ".egg/feedback-rules.md")

Other workflows in this repo (reusable-review.yml, on-mention.yml) follow a trusted checkout pattern: check out main first to run scripts that have access to secrets, then check out the PR branch for the agent. The comment in on-mention.yml explains why:

A malicious PR could replace this script to exfiltrate the bot token, and it would execute if the maintainer mentions the bot on that PR.

In this workflow, while no bash script is executed from the PR branch, the prompt construction embeds user-controlled content (.egg/feedback-rules.md) into the prompt. A malicious actor who can trigger this workflow could craft a .egg/feedback-rules.md that:

  • Attempts prompt injection to override agent behavior
  • Includes attacker-controlled instructions embedded in the feedback rules

Fix: Build the prompt from main before checking out the PR branch. Either remove the .egg/feedback-rules.md feature, or read it with explicit sanitization/length limits.

2. Insufficient Trigger Authorization

Lines 30-41: The workflow condition checks that the review/comment is from the bot account:

(github.event.review.user.login == 'james-in-a-box' || ...)

However, unlike on-mention.yml, there is no check that the PR author or sender is authorized. The on-mention.yml workflow has:

github.event.sender.login == 'jwbron' &&
github.event.sender.login != 'james-in-a-box'

Since the feedback workflow triggers on bot reviews, it seems like it should be safe. However, if anyone can trigger the bot to post a review comment containing egg-automated-review, they could indirectly cause this workflow to run. Verify that only trusted sources can cause a review to be posted with that marker.

Correctness Issues

3. PR Description Claims Non-Existent File

The PR description states:

action/build-feedback-prompt.sh: Minimal agent-mode prompt that tells the agent to read feedback, make fixes, verify locally, and push.

This file does not exist in this PR and is not in the repository. The prompt is built inline in the workflow YAML. The description is misleading.

4. Iteration Count Race Condition

Lines 128-141: The iteration count logic has a race condition:

feedback_count=$(gh api "repos/${{ github.repository }}/issues/${{ env.PR_NUMBER }}/comments" \
  --jq '[.[] | select(.body | test("egg-feedback-addressing"))] | length' ...)

if [[ "$feedback_count" -ge "$MAX_FEEDBACK_ROUNDS" ]]; then

The count is read before posting the marker comment (line 163), but:

  1. Two workflow runs could read the same count simultaneously
  2. Both proceed, post markers, and execute—bypassing the limit

The concurrency group (cancel-in-progress: true) mitigates this for concurrent runs on the same PR, but there's still a window between the count check and comment posting where a race can occur.

Fix: Either use atomic check-and-post (post the marker first, then count including it), or accept this as a known limitation documented in comments.

5. Inconsistent PR Number Resolution

Line 51: The PR number resolution is:

PR_NUMBER: ${{ github.event.pull_request.number || github.event.issue.number || github.event.inputs.pr_number }}

For pull_request_review events, the correct property is github.event.pull_request.number, which should work. However, the comment on the if block suggests this also handles issue_comment events where github.event.issue.number is correct. Verify this works for all three trigger paths.

Logic Issues

6. Feedback Rules Default Has Unescaped Heredoc

Lines 209-221: The default feedback rules use a heredoc with << not <<'EOF':

feedback_rules=$(cat << 'RULES_EOF'

This is actually correct (single quotes prevent expansion). However, the outer heredoc on line 238 (<< PROMPT_EOF without quotes) will expand variables. If $feedback_rules contains $, backquotes, or other special chars, they will be interpreted.

Fix: Change line 238 to << 'PROMPT_EOF' (with quotes) to prevent variable expansion in the template itself, then explicitly interpolate ${feedback_rules} where needed.

7. GraphQL minimizeComment May Fail Silently

Lines 167-179: The GraphQL mutation has || true but no logging of failures:

gh api graphql -f query='...' -f id="$node_id" || true

If minimization fails consistently (e.g., permissions issue), the workflow continues without any indication. Consider logging when this fails.

Minor Issues

8. Missing set -euo pipefail in Shell Steps

Most shell steps don't set strict mode (set -euo pipefail). Several existing workflows in the repo do use this. For consistency and safety, add it to shell steps that do meaningful work.

9. Hardcoded Bot Username

The bot username james-in-a-box is hardcoded in multiple places (line 53, lines 167-168, and the if condition). The BOT_USERNAME env var is defined but not used consistently. Either use the env var everywhere or remove it.

Lines using hardcoded value instead of env var:

  • Line 167: '.user.login == "james-in-a-box" or .user.login == "james-in-a-box[bot]"'
  • Lines 30-41: The if condition uses literal 'james-in-a-box'

10. workflow_dispatch Bypasses Most Safety Checks

Line 100: workflow_dispatch skips all filtering:

if [[ "$EVENT_NAME" == "workflow_dispatch" ]]; then
  echo "run=true" >> "$GITHUB_OUTPUT"
  exit 0
fi

This means a manual trigger bypasses the bot-author check, skip-review check (before line 107), and could run on arbitrary PRs. This is likely intentional for debugging but should be documented in the workflow comments.

Summary

The main issues are:

  1. Security: Missing trusted checkout pattern for prompt construction from PR content
  2. Correctness: PR description references non-existent file
  3. Race condition: Iteration counting can be bypassed under concurrent triggers

The security issue (#1) should be addressed before merging.

— Authored by egg

@james-in-a-box

james-in-a-box Bot commented Feb 8, 2026

Copy link
Copy Markdown
Contributor Author

Automated feedback loop has reached the maximum of 3 rounds. Human review is needed to make further progress on this PR.

@james-in-a-box

james-in-a-box Bot commented Feb 8, 2026

Copy link
Copy Markdown
Contributor Author

egg review completed. View run logs

@jwbron

jwbron commented Feb 8, 2026

Copy link
Copy Markdown
Owner

@james-in-a-box address this feedback #322 (review)

- Apply trusted checkout pattern: build prompt from main before checking
  out PR branch, preventing malicious .egg/feedback-rules.md injection
- Remove .egg/feedback-rules.md feature entirely (security risk)
- Use quoted heredoc ('PROMPT_EOF') and sed substitution to prevent
  variable expansion issues in prompt template
- Add set -euo pipefail to all shell steps for consistency
- Add logging for GraphQL minimizeComment failures
- Document iteration count race condition as known limitation
- Document workflow_dispatch bypass of safety checks
- Use BOT_USERNAME env var in shell steps (note: hardcoded in if
  condition because env vars unavailable at job level)

@james-in-a-box james-in-a-box Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed all feedback. Changes pushed in 614780c:

Security Issues

  1. Missing Trusted Checkout Pattern — Fixed. Now checks out main first to build the prompt, then checks out the PR branch. Removed .egg/feedback-rules.md feature entirely to eliminate prompt injection risk.

Correctness Issues

  1. PR Description References Non-Existent File — Fixed. Updated description to clarify prompt is built inline.
  2. Iteration Count Race Condition — Documented as known limitation with explanation of mitigation (concurrency group) and acceptable worst case (one extra round).
  3. Inconsistent PR Number Resolution — Verified working for all trigger paths (pull_request_review uses github.event.pull_request.number, issue_comment uses github.event.issue.number, workflow_dispatch uses input).

Logic Issues

  1. Heredoc Variable Expansion — Fixed. Using quoted heredoc (<< 'PROMPT_EOF') with sed substitution for controlled placeholders.
  2. GraphQL minimizeComment Failures — Added warning log when minimization fails.

Minor Issues

  1. Missing set -euo pipefail — Added to all shell steps.
  2. Hardcoded Bot Username — Used ${{ env.BOT_USERNAME }} in shell steps. Added comment explaining hardcoding in if condition is required (env vars unavailable at job level).
  3. workflow_dispatch Bypass — Documented with inline comment explaining intentional debugging behavior.

Issue #2 (Insufficient Trigger Authorization)

This is defense-in-depth: the workflow only triggers when the review contains egg-automated-review marker AND is from the bot account. External actors cannot forge reviews from the bot account. The on-mention.yml sender check is for a different threat model (maintainer-triggered actions on untrusted PRs).

— Authored by egg

@james-in-a-box

james-in-a-box Bot commented Feb 8, 2026

Copy link
Copy Markdown
Contributor Author

Automated feedback loop has reached the maximum of 3 rounds. Human review is needed to make further progress on this PR.

@james-in-a-box

james-in-a-box Bot commented Feb 8, 2026

Copy link
Copy Markdown
Contributor Author

egg finished successfully. View run logs

@james-in-a-box

james-in-a-box Bot commented Feb 8, 2026

Copy link
Copy Markdown
Contributor Author

No agent-mode design concerns.

This workflow follows the agent-mode design guidelines well:

  • Fetching: Agent fetches feedback itself via gh commands rather than having it pre-baked into the prompt
  • Output: No structured output requirements—agent addresses feedback and posts responses naturally
  • Actions: Agent pushes fixes and replies to comments directly (no post-processing pipeline)
  • Prompt focus: Objective-focused ("address feedback, push fixes") without micromanaging the procedure

The lightweight context (PR number, repo, which commands to use) is helpful orientation, not constraining pre-fetching.

— Authored by egg

@james-in-a-box

james-in-a-box Bot commented Feb 8, 2026

Copy link
Copy Markdown
Contributor Author

egg agent-mode-design completed. View run logs

jwbron
jwbron previously approved these changes Feb 8, 2026

@james-in-a-box james-in-a-box Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issues Found

1. Critical Bug: Multiline sed substitution fails (Lines 220-238)

The sed command used to substitute __FEEDBACK_RULES__ with the multiline feedback_rules variable will fail:

sed -i "s|__FEEDBACK_RULES__|${feedback_rules}|g" "$prompt_file"

sed operates line-by-line by default. When feedback_rules contains newlines (which it does), the s command becomes unterminated. This will cause the workflow step to fail with:

sed: -e expression #1, char XX: unterminated `s' command

Fix: Either:

  1. Use awk or a heredoc to build the file in one pass (preferred, simpler)
  2. Escape newlines in the variable: feedback_rules_escaped="${feedback_rules//$'\n'/\\n}"
  3. Write feedback_rules to a temp file and use sed -i '/pattern/r tempfile; /pattern/d'

Recommended approach—build the prompt without placeholder substitution:

prompt_file="${RUNNER_TEMP}/feedback-prompt-${PR_NUMBER}.txt"
cat > "$prompt_file" << PROMPT_EOF
Address review feedback on PR #${PR_NUMBER} in ${GITHUB_REPOSITORY}.

## Your Task
...
${feedback_rules}

## Conventions
...
PROMPT_EOF

This avoids the sed issue entirely by using shell variable expansion in the heredoc (note: remove single quotes from << PROMPT_EOF).


2. Minor: Missing --paginate for iteration count (Lines 159-160)

feedback_count=$(gh api "repos/${{ github.repository }}/issues/${{ env.PR_NUMBER }}/comments" \
  --jq '[.[] | select(.body | test("egg-feedback-addressing"))] | length' 2>/dev/null || echo "0")

Without --paginate, the API returns at most 30 comments per page. If a PR has >30 comments, the iteration count could be incorrect, potentially allowing more than MAX_FEEDBACK_ROUNDS iterations.

Fix: Add --paginate and use --slurp to combine pages:

feedback_count=$(gh api "repos/${{ github.repository }}/issues/${{ env.PR_NUMBER }}/comments" \
  --paginate --slurp \
  --jq '[.[][] | select(.body | test("egg-feedback-addressing"))] | length' 2>/dev/null || echo "0")

Note: The existing reusable-review.yml has the same issue—consistency is reasonable here, but this is a known gap.


3. Observation: workflow_dispatch bypasses safety checks (Lines 106-110)

The workflow_dispatch trigger intentionally bypasses the bot-author check, skip-review check, and iteration limit. This is documented but worth highlighting:

  • Anyone with write access can trigger the workflow on any PR
  • The iteration limit is bypassed, so manual triggers could run indefinitely

The code comment explains this is for debugging, which is reasonable. No change needed, but consider adding a comment in the PR description about this behavior for future maintainers.


4. Minor: Error handling in result comment step (Lines 308-319)

The "Post result comment" step runs on always() && !cancelled() && steps.should-run.outputs.run == 'true', but uses steps.egg.outcome which may be empty if the egg step didn't run (e.g., if an earlier step failed after should-run returned true).

If steps.egg.outcome is empty (not "success"), the message says "egg failed to address feedback" which is misleading if the failure was in checkout or prompt building.

Suggestion: Check for specific failures:

if [[ "${{ steps.egg.outcome }}" == "success" ]]; then
  BODY="egg feedback addressed. ..."
elif [[ "${{ steps.egg.outcome }}" == "failure" ]]; then
  BODY="egg failed to address feedback. ..."
else
  BODY="Workflow failed before running egg. ..."
fi

Summary

The multiline sed bug (issue #1) is blocking—the workflow will fail on every run. The other issues are minor improvements.

— Authored by egg

@james-in-a-box

james-in-a-box Bot commented Feb 8, 2026

Copy link
Copy Markdown
Contributor Author

Automated feedback loop has reached the maximum of 3 rounds. Human review is needed to make further progress on this PR.

@james-in-a-box

james-in-a-box Bot commented Feb 8, 2026

Copy link
Copy Markdown
Contributor Author

egg review completed. View run logs

@jwbron

jwbron commented Feb 8, 2026

Copy link
Copy Markdown
Owner

@james-in-a-box address this feedback: #322 (review)

- Replace sed placeholder substitution with heredoc variable expansion
  to fix multiline substitution failure (sed can't handle newlines in
  replacement strings)
- Add --paginate --slurp to iteration count API call to correctly count
  feedback rounds on PRs with >30 comments
- Improve result comment step to distinguish between egg failure and
  workflow failure before egg ran

Authored-by: egg
@james-in-a-box

james-in-a-box Bot commented Feb 8, 2026

Copy link
Copy Markdown
Contributor Author

Addressed all feedback from the review.

Changes Made

1. Fixed critical multiline sed bug (Lines 226-277)

The sed command for substituting __FEEDBACK_RULES__ would fail because sed operates line-by-line and can't handle multiline content in replacement strings.

Fix: Replaced the placeholder substitution approach with direct heredoc variable expansion. The prompt is now built in one pass using << PROMPT_EOF (without single quotes) so shell variables are expanded directly. This eliminates the need for sed entirely and is simpler.

2. Added pagination to iteration count (Lines 165-170)

The API call to count feedback-addressing runs would miss runs on PRs with >30 comments (GitHub's default page size).

Fix: Added --paginate --slurp flags. The --slurp combines paginated results into a nested array, so the jq selector was updated from .[] to .[][].

3. Improved error handling in result comment (Lines 310-316)

The step previously only distinguished between egg success and "everything else", which could misleadingly report "egg failed" when the workflow failed before the egg step ran.

Fix: Added a third case to detect when steps.egg.outcome is empty (neither "success" nor "failure"), indicating the workflow failed before reaching the egg step.

— Authored by egg

@james-in-a-box

james-in-a-box Bot commented Feb 8, 2026

Copy link
Copy Markdown
Contributor Author

Agent-mode design review: No concerns.

The workflow follows agent-mode design principles well:

  • No excessive pre-fetching: Prompt provides only lightweight metadata (PR number, repo name) and directs the agent to fetch feedback via gh pr view and gh api commands. This is appropriate orientation, not constraining pre-fetching.
  • No structured output requirements: Agent uses natural language for PR comments and pushes code directly.
  • No post-processing pipeline: Agent takes actions directly via gh and git commands.
  • What over how: Clear objective ("address review feedback") with context about where to find feedback, but procedure is left to agent judgment.
  • Security handled at sandbox level: Trusted-checkout pattern prevents prompt injection from malicious PRs - this is proper infrastructure enforcement rather than prompt-level restrictions.

— Authored by egg

@james-in-a-box

james-in-a-box Bot commented Feb 8, 2026

Copy link
Copy Markdown
Contributor Author

egg agent-mode-design completed. View run logs

@james-in-a-box james-in-a-box Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-Review Summary

This is a re-review following fixes pushed in d6efa16. The previous review at 614780ce00ab72d3d5b54fe74a1678f2f79b8324 identified three issues. This review verifies those fixes and examines the current state.


Previous Issues — Status

1. Multiline sed bug (Critical) — ✅ Fixed

The sed placeholder substitution has been replaced with direct heredoc variable expansion (lines 235-270). The prompt is now built in one pass using << PROMPT_EOF (unquoted, allowing shell expansion) with explicit ``` escaping for command examples. This is the correct approach.

2. Missing --paginate for iteration count — ✅ Fixed

Lines 168-170 now include --paginate --slurp and the jq selector correctly uses .[][] to flatten the nested array from paginated results.

3. Improved result comment error handling — ✅ Fixed

Lines 310-316 now distinguish between three cases: egg success, egg failure, and workflow failure before egg ran (when steps.egg.outcome is neither "success" nor "failure").


New Issue Found

1. Heredoc indentation creates malformed prompt (Correctness)

Lines 235-270: The heredoc content is indented with spaces/tabs to match the YAML structure:

      - name: Build feedback prompt
        ...
        run: |
          ...
          cat > "$prompt_file" << PROMPT_EOF
          Address review feedback on PR #${PR_NUMBER} in ${GITHUB_REPOSITORY}.

          ## Your Task
          ...

When using << PROMPT_EOF (without the - operator), the heredoc content includes the leading whitespace. The resulting prompt file will have every line prefixed with extra spaces, making it poorly formatted.

Compare to on-check-failure.yml which runs the prompt builder script (bash action/build-autofixer-prompt.sh), and reusable-review.yml which does the same. These scripts write prompts without embedded indentation issues.

Fix options:

  1. Use <<- PROMPT_EOF (with hyphen) and use tabs for indentation — bash will strip leading tabs
  2. Start the heredoc content at column 0 (no leading whitespace) — works but looks ugly in YAML
  3. Move prompt building to a separate script (matches pattern in other workflows)
  4. Use sed or parameter expansion to strip leading whitespace

Recommended: Option 3 (create action/build-feedback-prompt.sh) to match the pattern used elsewhere. This also allows testing the prompt builder independently.


Observations (Non-blocking)

  1. Pattern divergence: This workflow builds the prompt inline in YAML while on-check-failure.yml and reusable-review.yml use external scripts. The inline approach works but is harder to test and maintain. Consider aligning with the script-based pattern.

  2. No EGG_BOT_NAME marker in result comment: The result comment at lines 304-319 doesn't include the egg-automated-review marker that other workflows use. This isn't a functional issue but breaks the pattern used for iteration counting and marker detection.

  3. workflow_dispatch bypass is documented: The inline comment at line 112-114 explains the intentional debugging bypass. This is acceptable.


Verdict

The critical multiline sed bug is fixed, as are the pagination and error handling issues. However, the heredoc indentation issue (new issue #1) means the prompt will be malformed with leading whitespace on every line. This should be fixed before merging.

— Authored by egg

@james-in-a-box

james-in-a-box Bot commented Feb 8, 2026

Copy link
Copy Markdown
Contributor Author

egg review completed. View run logs

@james-in-a-box

This comment has been minimized.

@jwbron

jwbron commented Feb 8, 2026

Copy link
Copy Markdown
Owner

Address the feedback here: #322 (review)

The inline heredoc in the workflow YAML was indented to match the YAML
structure, causing leading whitespace to be included in the generated
prompt. This created malformed prompts with every line prefixed with
spaces.

Fix by extracting prompt building to action/build-feedback-prompt.sh,
matching the pattern used by on-check-failure.yml and reusable-review.yml.
This also makes the prompt easier to test independently.
@james-in-a-box

james-in-a-box Bot commented Feb 8, 2026

Copy link
Copy Markdown
Contributor Author

Fixed the heredoc indentation issue. Changes pushed in 30f90bf:

1. Heredoc indentation creates malformed prompt — Fixed.

Moved prompt building from inline YAML to action/build-feedback-prompt.sh, matching the pattern used by on-check-failure.yml and other workflows. This eliminates the indentation issue entirely since the script writes the prompt directly without YAML indentation artifacts.

The script:

  • Uses echo "$prompt" > "$prompt_file" to write the prompt without heredoc indentation issues
  • Sets the required $GITHUB_OUTPUT variables for the workflow
  • Follows the same structure as build-autofixer-prompt.sh

2. No EGG_BOT_NAME marker in result comment — Skipped (non-blocking observation).

Other workflows (on-check-failure.yml, reusable-review.yml, on-mention.yml) also don't include the egg-automated-review marker in their result comments, so this is consistent with existing patterns.

— Authored by egg

@james-in-a-box

james-in-a-box Bot commented Feb 8, 2026

Copy link
Copy Markdown
Contributor Author

egg feedback addressed. View run logs

@james-in-a-box

james-in-a-box Bot commented Feb 8, 2026

Copy link
Copy Markdown
Contributor Author

Agent-Mode Design Review: Approved ✓

No agent-mode design concerns.

The design follows agent-mode principles well:

  • Minimal context, agent-driven fetching: Prompt provides only PR number/repo, agent fetches feedback and diffs itself
  • Direct action: Agent pushes code and posts comments directly—no JSON output or post-processing pipeline
  • Objective-focused: Describes what to accomplish with guidelines on fix/respond/skip priorities, without micromanaging procedure

— Authored by egg

@james-in-a-box

james-in-a-box Bot commented Feb 8, 2026

Copy link
Copy Markdown
Contributor Author

egg agent-mode-design completed. View run logs

@james-in-a-box james-in-a-box Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-Review Summary

This review covers changes since commit d6efa16 (the previous review).


Previous Issue — Status

Heredoc indentation creates malformed prompt — ✅ Fixed

The inline heredoc has been replaced with an external script action/build-feedback-prompt.sh. This is the correct fix:

  1. Follows established pattern: Matches build-autofixer-prompt.sh structure and approach
  2. Eliminates indentation issue: The script uses echo "$prompt" > "$prompt_file" which correctly preserves the prompt formatting without YAML indentation artifacts
  3. Passes syntax checks: Both bash -n and shellcheck pass cleanly

New Code Review

action/build-feedback-prompt.sh

Correctness: The script correctly:

  • Uses set -euo pipefail for strict error handling
  • Validates required environment variables (PR_NUMBER, GITHUB_REPOSITORY)
  • Writes outputs to $GITHUB_OUTPUT with fallback to /dev/null
  • Uses ${RUNNER_TEMP:-/tmp} for portable temp directory handling

Pattern consistency: Matches build-autofixer-prompt.sh in:

  • Header documentation format
  • Function structure (build_prompt main function)
  • Environment variable validation approach
  • Output file naming convention

Minor observation (non-blocking): The script doesn't load any conventions file like build-autofixer-prompt.sh does with autofixer-conventions.md. This is fine since the feedback addressing task has simpler conventions that are inline in the prompt.

.github/workflows/on-review-feedback.yml

The workflow change from inline heredoc to bash action/build-feedback-prompt.sh is correct. The PR_NUMBER env var is explicitly passed, and GITHUB_REPOSITORY is available as a default GitHub Actions environment variable.


Verdict

The heredoc indentation issue from the previous review has been properly fixed by extracting the prompt building to an external script. The implementation follows established patterns in the codebase.

— Authored by egg

@james-in-a-box

james-in-a-box Bot commented Feb 8, 2026

Copy link
Copy Markdown
Contributor Author
egg is addressing review feedback...

@james-in-a-box

james-in-a-box Bot commented Feb 8, 2026

Copy link
Copy Markdown
Contributor Author

egg review completed. View run logs

@james-in-a-box

james-in-a-box Bot commented Feb 8, 2026

Copy link
Copy Markdown
Contributor Author

Workflow failed before running egg. View run logs

@jwbron
jwbron merged commit 94743bc into main Feb 8, 2026
19 of 20 checks passed
github-actions Bot pushed a commit that referenced this pull request Feb 8, 2026
Update documentation to reflect the new automated review feedback workflow
added in commit 94743bc (PR #322):

- action/README.md: Add build-feedback-prompt.sh to files table
- docs/development/STRUCTURE.md: Add build-feedback-prompt.sh to action directory listing
- docs/guides/github-automation.md: Add full "Address Review Feedback" section documenting the workflow, triggers, iteration limiting, and security model

The new workflow enables automated review loops (PR → review → address feedback → re-review) for bot-authored PRs, with circuit breaker protection to prevent infinite loops.

Authored-by: egg
jwbron added a commit that referenced this pull request Feb 8, 2026
* docs: Add review feedback workflow to documentation

Update documentation to reflect the new automated review feedback workflow
added in commit 94743bc (PR #322):

- action/README.md: Add build-feedback-prompt.sh to files table
- docs/development/STRUCTURE.md: Add build-feedback-prompt.sh to action directory listing
- docs/guides/github-automation.md: Add full "Address Review Feedback" section documenting the workflow, triggers, iteration limiting, and security model

The new workflow enables automated review loops (PR → review → address feedback → re-review) for bot-authored PRs, with circuit breaker protection to prevent infinite loops.

Authored-by: egg

* docs: Remove misleading reference to .egg/feedback-rules.md

The documentation incorrectly stated that custom rules could be provided
via `.egg/feedback-rules.md`. Unlike build-review-prompt.sh which reads
.egg/review-rules.md, build-feedback-prompt.sh has no such functionality.

Removed the misleading line to prevent users from expecting behavior that
doesn't exist.

Authored-by: egg

---------

Co-authored-by: jwbron <8340608+jwbron@users.noreply.github.com>
Co-authored-by: james-in-a-box[bot] <246424927+james-in-a-box[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant